package org.rain.core.api;

import org.rain.common.CommonApi;
import org.rain.common.exception.BaseException;
import org.rain.common.model.LoginUser;
import org.rain.common.util.Colls;
import org.rain.core.sys.mapper.SysDictMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * created by yangtong on 2025/4/10 13:40:07
 * <br/>
 * 默认的公共API方法
 */
@Component
public class DefaultApiImpl implements CommonApi {

    @Autowired
    private SysDictMapper sysDictMapper;

    @Override
    public LoginUser getCurrent() throws BaseException {
        return null;
    }

    @Override
    public List<String> getCurrentRoleCodes() {
        return List.of();
    }

    @Override
    public String getDictText(String dictCode, String dictValue) {
        return "";
    }

    @Override
    public List<Map<String, Object>> queryColumn(String table, String column, @NonNull List<?> value, String... queryColumnArr) {
        if (Colls.isEmpty(value)) {
            throw new BaseException("value的长度必须大于0");
        }
        return sysDictMapper.translateByTable(table, column, value, queryColumnArr);
    }

    @Override
    public String getSysConfig() {
        return "";
    }
}
